package com.leetcode.leetcode2;

/**
 *  删除有序数组中的重复项
 * @author: luhd
 * @create: 2021-09-12
 */
public class Practice26 {
    public static void main(String[] args) {
        int[] nums = {0,0,1,1,1,2,2,3,3,4};
        //int[] nums = {1,1,2};
        removeDuplicates(nums);
    }
    public static int removeDuplicates(int[] nums) {
        if(nums.length<2) return 1;
        int left = 0;
        int right = 1;
        while(right<nums.length){
            if(nums[left]!=nums[right]){
                nums[++left] = nums[right++];
            }else{
                right++;
            }
        }
        for (int i = 0; i < left+1; i++) {
            System.out.print(nums[i]+",");
        }
        return left+1;
    }
}
